/**
 * @title CalendarActivity.java
 * @package com.esun.cheetah.view.match.matchlist
 * @description 日历界面
 * @author liugan
 * @date 2012-4-14
 * @copyright 深圳市易讯天空
 */
package com.esun.cheetah.view.match.matchlist;

import com.esun.cheetah.R;
import com.esun.cheetah.view.custom.calendar.CalendarView;
import com.esun.cheetah.view.custom.calendar.CalendarView.OnCellTouchListener;
import com.esun.cheetah.view.custom.calendar.CalendarView.OnMonthChangeListener;
import com.esun.util.TimeUtil;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

/**
 * @title CalendarActivity
 * @description 日历选择界面
 * @author liugan
 */
public class CalendarActivity extends Activity {
	public static String YEAR = "YEAR";
	public static String MONTH = "MONTH";
	public static String DAY = "DAY";

	private Button backButton;
	private Button todayButton;
	private CalendarView mCalendar;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.calendar_activity);
		initSubView();
	}

	/**
	 * @title initSubViewFields
	 * @description
	 */
	private void initSubView() {
		backButton = (Button) findViewById(R.id.btn_calendar_back);
		todayButton = (Button) findViewById(R.id.btn_calendar_today);
		mCalendar = (CalendarView) findViewById(R.id.cv_calendar);
		backButton.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				finish();
			}
		});

		todayButton.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				mCalendar.goToday();

			}
		});

		mCalendar.setOnCellTouchListener(new OnCellTouchListener() {

			@Override
			public void onTouch(int year, int month, int day) {
				Intent intent = new Intent();
				intent.putExtra(YEAR, year);
				intent.putExtra(MONTH, month);
				intent.putExtra(DAY, day);
				setResult(0, intent);
				finish();
			}

		});

		mCalendar.setOnMonthChangeListener(new OnMonthChangeListener() {

			@Override
			public void onMonthChange(int year, int month) {
				if (TimeUtil.getInstance().isCurrentMonth(year, month)) {
					todayButton.setVisibility(View.INVISIBLE);
				} else {
					todayButton.setVisibility(View.VISIBLE);
				}

			}
		});

		todayButton.setVisibility(View.INVISIBLE);

	}

}
